package sk.tuke.constraintbuilder.editor.providers;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import sk.tuke.constraintbuilder.model.Annotation;
import sk.tuke.constraintbuilder.model.Choice;
import sk.tuke.constraintbuilder.model.ConditionsElement;
import sk.tuke.constraintbuilder.model.INodeElement;
import sk.tuke.constraintbuilder.model.RuleElement;
import sk.tuke.constraintbuilder.model.Not;
import sk.tuke.constraintbuilder.model.RulesElement;
import sk.tuke.constraintbuilder.model.SimpleRuleElement;
import sk.tuke.constraintbuilder.model.TopElement;
import sk.tuke.constraintbuilder.model.Value;
import sk.tuke.constraintbuilder.utils.MyImages;

public class ConstraintTreeLabelProvider extends LabelProvider {
	
	@Override
	public String getText(Object element) {
		if (element instanceof ConditionsElement) return "Condition";
		else if (element instanceof RulesElement) return "Rule";
		else if (element instanceof String) return (String) element;
		else if (element instanceof Value) return ((Value) element).getValue();
		else if (element instanceof Annotation) return ((Annotation) element).getName();
		else if (element instanceof SimpleRuleElement){
			String elementName = element.getClass().getSimpleName();
			Integer value = ((SimpleRuleElement) element).getValue();
			return elementName+": "+String.valueOf(value);
		}
		else if (element instanceof RuleElement){
			String elementName = element.getClass().getSimpleName();
			return elementName;
		}
		else if (element instanceof INodeElement){
			String elementName = element.getClass().getSimpleName();
			return elementName;
		}
		else return null;
	}

	@Override
	public Image getImage(Object element) {
		if (element instanceof TopElement) {
			return MyImages.TOP;
		}
		if(element instanceof Annotation){
			return MyImages.ANNOTATION;
		}
		if(element instanceof Choice){
			return MyImages.CHOICE;
		}
		if(element instanceof Not){
			return MyImages.NOT;
		}
		return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
	}

}
